import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
  final PageController _controller = PageController();
  List<Widget> _pages = <Widget>[
    Container(color: Colors.red,key: Key("0"),alignment: Alignment.center,child: Text("1"),),
    Container(color: Colors.green,key: Key("1"),alignment: Alignment.center,child: Text("2"),),
    Container(color: Colors.blue,key: Key("2"),alignment: Alignment.center,child: Text("3"),),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          width: 400,
          height: 200,
          child: PageView(
            controller: _controller,
            children: _pages.map((Widget page) {
              // return GestureDetector(
              //   onTap: (){
              //     setState(() {
              //       _pages.remove(page);
              //     });
              //   },
              //   child: AnimatedSwitcher(
              //     duration: const Duration(seconds: 3),
              //     transitionBuilder: (Widget child, Animation<double> animation) {
              //       return ScaleTransition(scale: animation, child: child);
              //     },
              //     child: page,
              //   ),
              // );
              return GestureDetector(
                onTap: (){
                  setState(() {
                    _pages.remove(page);
                  });
                },
                child: AnimatedSwitcher(
                  duration: const Duration(seconds: 3),
                  transitionBuilder: (Widget child, Animation<double> animation) {
                    return ScaleTransition(scale: animation, child: child);
                  },
                  child: Dismissible(
                    direction: DismissDirection.vertical,
                    key: ValueKey(page),
                    onDismissed: (DismissDirection direction) {
                      print("12121213123123=====$page");
                      _pages.remove(page);
                      // _controller.jumpToPage(_pages.length - 1);

                      setState(() {
                      });
                    },
                    child: page,
                  ),
                ),
              );
            }).toList(),
          ),
        ),
      ),
    );
  }
}